package com.app.utils;


import android.annotation.SuppressLint;
import android.text.format.DateFormat;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@SuppressLint("SimpleDateFormat")
public class TimeUtil

{
	private static SimpleDateFormat sf = null;

	/**
	 * ��ȡϵͳʱ�� ��ʽΪ��"yyyy/MM/dd "
	 * */
	public static String getCurrentDate() {
		Date d = new Date();
		sf = new SimpleDateFormat("yyyy/MM/dd");
		return sf.format(d);
	}

	/**
	 * ʱ���ת�����ַ�
	 * */
	public static String getDateToString(long time) {
		Date d = new Date(time);
		sf = new SimpleDateFormat("yyyy-MM-dd");
		return sf.format(d);
	}

	/* ���ַ�תΪʱ��� */
	public static long getStringToDate(String time) {
		sf = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		try {
			date = sf.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
			return 0;
		}
		return date.getTime();

	}

	public static String formatDateWithHH(long time) {
		Date d = new Date(time);
		sf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		return sf.format(d);
	}
	
	public static String formatDateWithHHSS(long time) {
		Date d = new Date(time);
		sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sf.format(d);
	}
	
	public static long _SysTime(String sysTime) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		long _systime = 0;
		String localSysTime = df.format(new Date());
		try {
			Date d1 = df.parse(localSysTime);
			Date d2 = df.parse(sysTime);
			 _systime = (d1.getTime() - d2.getTime()) / 1000;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return _systime;
	}
	
	public static long leaveTime(String createTime, long _systime) {
		long leaveTime = 0;
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String localSysTime = df.format(new Date());
		try {
			Date d1 = df.parse(localSysTime);
		    Date d2 = df.parse(formatDateWithHHSS(Long.parseLong(createTime)));
			leaveTime = (d1.getTime() / 1000 - _systime) - d2.getTime() / 1000;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return leaveTime;
	}


}